import { Node_CONTRACT, NodeABI, fullHost } from './index'
import { TronWeb, utils as TronWebUtils, Trx, TransactionBuilder, Contract, Event, Plugin } from 'tronweb';

export const IsUserExists = async (userAddr) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .isUserExists(userAddr)
        .call()
}

export const Id2Address = async (id) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .id2Address(id)
        .call()
}


export const UserInfo = async (userAddr) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .userInfo(userAddr)
        .call()
}



export const GetDirectsByPage = async (address, pageNum, pageSize) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .getDirectsByPage(address, pageNum, pageSize)
        .call()
}


export const GetNFTsInfo = async (tokenIds) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .getNFTsInfo(tokenIds)
        .call()
}

export const Count = async () => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .count()
        .call()
}

export const GetNodeUSDT = async (curCount) => {
    const tronWeb = new TronWeb({
        fullHost: fullHost,
    })
    tronWeb.setAddress(Node_CONTRACT)
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .getNodeUSDT(curCount)
        .call()
}


export const GetNodeTRX = async (curCount) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .getNodeTRX(curCount)
        .call()
}


export const PayUSDT = async (address, nodeNum) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .payUSDT(address, nodeNum)
        .send(
            {
                feeLimit: 9000_000_000,
            }
        )
}

export const PayTRX = async (address, nodeNum, payable) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .payTRX(address, nodeNum)
        .send({ callValue: payable })
}


export const GetRewardUSDT = async () => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .getRewardUSDT()
        .send()
}

export const GetRewardTRX = async () => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .getRewardTRX()
        .send()
}

export const GetReleaseReward = async (id) => {
    return tronWeb
        .contract(NodeABI, Node_CONTRACT)
        .getReleaseReward(id)
        .send(
            {
                shouldPollResponse: true,
                pollTimes: 1
            }
        )
}



